package com.wangxiang.sys.manage.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.wangxiang.common.utils.PageEntity;
import com.wangxiang.sys.manage.feign.ProductFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wangxiang.sys.manage.entity.AuditLogEntity;
import com.wangxiang.sys.manage.service.AuditLogService;
import com.wangxiang.common.utils.PageUtils;
import com.wangxiang.common.utils.R;



/**
 * 
 *
 * @author wangxiang
 * @email 2293672863@qq.com
 * @date 2022-04-19 14:35:03
 */
@RestController
@RequestMapping("sys/auditlog")
public class AuditLogController {
    @Autowired
    private AuditLogService auditLogService;
    @Autowired
    ProductFeign productFeign;

    @RequestMapping("pass")
    public R pass(@RequestBody HashMap<String , Object> map){
//        System.out.println(map);
        int i = auditLogService.passInsert(map);
        if (i==0){
            return R.error("操作失败，三表操作系统错误，请检查审核表，日志表和商品表同步情况");
        }
        HashMap<String, Integer> proMap = new HashMap<>();

        proMap.put("spuId",i);
        proMap.put("status",0);
        int update = productFeign.auditRecover(proMap);
        if (update==0){
            return R.error("商品表。spu,sku同步失败");
        }
        return R.ok().put("msg","操作成功").put("code",800);

    }

    @RequestMapping("invalid")
    public R invalid(@RequestBody HashMap<String , Object> map){
        String nullStr = "";
        if (map.get("remark")==nullStr|nullStr.equals(map.get("remark"))|map.get("remark")==" "){
            return R.error("你未填写违规原因");
        }
        int userId = Integer.valueOf(map.get("userId").toString());
        int orderId = Integer.valueOf(map.get("orderId").toString());
        String remark = map.get("remark").toString();

        int i = auditLogService.invalidShop(orderId, userId, remark);
        if (i==0){
            return R.error("操作失败，三表操作系统错误，请检查审核表，日志表和商品表同步情况");
        }
        HashMap<String, Integer> proMap = new HashMap<>();
        proMap.put("spuId",i);
        proMap.put("status",4);
        int i1 = productFeign.auditRecover(proMap);
        if (i1==0){
            return R.error("商品表。spu,sku同步失败");
        }
        return R.ok().put("msg","操作成功").put("code",800);


    }
    @RequestMapping("page")
    public R page(@RequestBody HashMap<String , Integer> map){
        PageEntity page = auditLogService.page(map);
        List<HashMap<String, Object>> list = auditLogService.pageList((List<AuditLogEntity>) page.getList());
        List<HashMap<String, Object>> auditshop = productFeign.auditshop(list);

        return R.ok().put("list",auditshop).put("page",page);
    }




}
